const {
  ObserverList
} = require('../../pages/common.js');
const utils = require('../../libs/undescore-1.8.3.js');

module.exports = (config) => {
  const { im } = config;
  let watcher = new ObserverList();
  let disconnect = () => {
    im.disconnect();
  };
  let connect = (user) => {
    im.watch({
      status({ status }) {
        watcher.notify(status);
      },
      message() {
        // console.log(message);
      }
    })
    return im.connect(user);
  };

  let watch = (watch) => {
    var force = true;
    watcher.add(watch, force);
  };

  return {
    disconnect,
    connect,
    watch,
  };
};